package vip.web3.api.service.impl.biz;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.web3.api.dao.biz.ProductDao;
import vip.web3.api.entity.biz.ProductEntity;
import vip.web3.api.service.biz.ProductService;
import vip.web3.common.enums.StatusEnum;

import java.math.RoundingMode;
import java.util.List;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao, ProductEntity> implements ProductService {
    @Override
    public List<ProductEntity> listProducts() {
        List<ProductEntity> list = this.lambdaQuery()
                .eq(ProductEntity::getStatus, StatusEnum.OPEN.getCode())
                .orderByAsc(ProductEntity::getSort)
                .list();
        for (ProductEntity product : list) {
            product.setPriceCny(product.getPriceCny().setScale(2, RoundingMode.DOWN));
            product.setPriceUsdt(product.getPriceUsdt().setScale(2, RoundingMode.DOWN));
            product.setRate(product.getRate().setScale(3, RoundingMode.DOWN));
        }
        return list;
    }
}
